﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{ 
    [Route("api/[controller]")]
    [ApiController]
    public class CollectiveController : ControllerBase
    {  
        private readonly DZJDBcontext db;
        /// <summary>
        /// 数据库
        /// </summary>
         
        public CollectiveController(DZJDBcontext context) 
        { 
            db = context;
        }
        [HttpGet]
        public List<EM_Collective> GetAll()
        {
            //select * from EM_Collective 查找
            return db.EM_Collective.ToList();
        }
        [HttpPost]
        public bool Add(EM_Collective em_Collective)
        {
            //sql insert into  set em_Collective Activityclass=20  班级活动人数增加
            db.EM_Collective.Add(em_Collective);

            int result = db.SaveChanges();
            return result > 0 ? true : false;
        }

        [HttpDelete]
        public bool Delete(Guid ID)
        {
            EM_Collective? em_Collective = new EM_Collective();
            em_Collective = db.EM_Collective.Where(a => a.Activityschool==1).SingleOrDefault();

            int result = 0;
            if (em_Collective!=null)
            {
                //sql update...
                db.EM_Collective.Remove(em_Collective);
                result = db.SaveChanges();
            }


            
            return result > 0 ? true : false;
        }


    }
}
